package data
{
	import events.VectorDataEvent;
	
	import flash.events.EventDispatcher;

	public class VectorData extends EventDispatcher
	{
		private var _vector:Vector.<Object> = new Vector.<Object>;
		private var _index:int;
		
		public function VectorData()
		{
			super();
			_vector = new Vector.<Object>();
		}
		
		public function push(value:Object):void
		{
			_vector.push(value);
			dispatchEvent(new VectorDataEvent(VectorDataEvent.ADD,value));
		}
		
		public function pop():Object
		{
			var result:Object = _vector.pop();
			dispatchEvent(new VectorDataEvent(VectorDataEvent.REMOVE,result));
			return result;
		}
		
		public function remove(value:Object):void
		{
			if(_vector.indexOf(value)>-1)
			{
				_vector.splice(_vector.indexOf(value),1);
				dispatchEvent(new VectorDataEvent(VectorDataEvent.REMOVE,value));
			}
		}
		
		public function clear():void
		{
			for each(var item:Object in _vector)
			{
				remove(item);
			}
		}
		
		public function next():Object
		{
			return _vector[_index++];
		}
		
		public function hasNext():Boolean
		{
			return _index < _vector.length;
		}
		
		public function reset():void
		{
			_index = 0;
		}
		
		public function preview():Object
		{
			return _vector[_index--];
		}
	}
}